CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0 FATAL_ERROR)
PROJECT(utils)

IF(OS_WINDOWS)
  SET(PLATFORM_HEADER)
  SET(PLATFORM_SOURCES)
  SET(PLATFORM_LIBRARIES)
ELSEIF(OS_LINUX)
  SET(PLATFORM_HEADER)
  SET(PLATFORM_SOURCES)
  SET(PLATFORM_LIBRARIES)
ELSEIF(OS_POSIX)
  SET(PLATFORM_HEADER)
  SET(PLATFORM_SOURCES)
  SET(PLATFORM_LIBRARIES)
ENDIF(OS_WINDOWS)

IF(USE_PTHREAD)
  IF(NOT OS_ANDROID)
   SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} pthread)
  ENDIF(NOT OS_ANDROID)
ENDIF(USE_PTHREAD)

SET(HEADERS
  ${CMAKE_SOURCE_DIR}/src/utils/chunk_info.h
  ${CMAKE_SOURCE_DIR}/src/utils/m3u8_reader.h
  ${CMAKE_SOURCE_DIR}/src/utils/m3u8_writer.h
)

SET(SOURCES
  ${CMAKE_SOURCE_DIR}/src/utils/chunk_info.cpp
  ${CMAKE_SOURCE_DIR}/src/utils/m3u8_reader.cpp
  ${CMAKE_SOURCE_DIR}/src/utils/m3u8_writer.cpp
)

SET(UTILS_SOURCES ${HEADERS} ${SOURCES})
SET(UTILS_LIBRARIES ${COMMON_BASE_LIBRARY})
SET(INCLUDE_DIRECTORIES_UTILS
  ${INCLUDE_DIRECTORIES_UTILS}
  ${CMAKE_SOURCE_DIR}/src
  ${COMMON_INCLUDE_DIRS}
)

ADD_LIBRARY(${PROJECT_NAME} STATIC ${UTILS_SOURCES})
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE ${INCLUDE_DIRECTORIES_UTILS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${UTILS_LIBRARIES})

IF (DEVELOPER_CHECK_STYLE)
  SET(CHECK_SOURCES ${UTILS_SOURCES})
  REGISTER_CHECK_STYLE_TARGET(check_style_utils "${CHECK_SOURCES}")
  REGISTER_CHECK_INCLUDES_TARGET(${PROJECT_NAME})
ENDIF(DEVELOPER_CHECK_STYLE)

IF(DEVELOPER_ENABLE_TESTS)
  FIND_PACKAGE(GTest REQUIRED)
  SET(UTILS_UNIT_TEST "utils_unit_tests")
  SET(PRIVATE_INCLUDE_DIRECTORIES_UTILS_TESTS
    ${PRIVATE_INCLUDE_DIRECTORIES_UTILS_TESTS}
    ${CMAKE_SOURCE_DIR}/src
  )
  SET(UTILS_TESTS_LIBS ${PROJECT_NAME} ${GTEST_BOTH_LIBRARIES} ${PLATFORM_LIBRARIES})
  ADD_EXECUTABLE(${UTILS_UNIT_TEST}
    ${CMAKE_SOURCE_DIR}/tests/utils/unit_test_utils.cpp
  )
  TARGET_INCLUDE_DIRECTORIES(${UTILS_UNIT_TEST} PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES_UTILS_TESTS})
  TARGET_COMPILE_DEFINITIONS(${UTILS_UNIT_TEST} PRIVATE -DPROJECT_TEST_SOURCES_DIR="${CMAKE_SOURCE_DIR}/tests")
  TARGET_LINK_LIBRARIES(${UTILS_UNIT_TEST} ${UTILS_TESTS_LIBS})
  ADD_TEST_TARGET(${UTILS_UNIT_TEST})
  SET_PROPERTY(TARGET ${UTILS_UNIT_TEST} PROPERTY FOLDER "Utils unit tests")
ENDIF(DEVELOPER_ENABLE_TESTS)
